Top = ${shell pwd}
App = ${Top}/Application
BootLoader = ${Top}/Bootloader
Settings = ${Top}/Settings
GenerateBin = $(Top)/GenerateBin
#Bin = ${Top}/Bin

export PRODUCT_A = y
export PRODUCT_B = n

all:  gd32 setting generate

setting: Makefile
	make -C ${Settings}
	cd ${Settings} && ./build/settings

gd32: Makefile
	make -C ${App}
	make -C ${BootLoader}

generate:
	make -C $(GenerateBin)	
	cd ${GenerateBin} && ./build/generate

# cp ${BootLoader}/build/BootLoader.bin ${Top}/BinFiles/
# cp ${App}/build/Application.bin ${Top}/BinFiles/
	
# amp:
# 	cd ${Amp} && ./ampcreater
# 	cd ${AllBin} && ./allinone

clean:
	rm -rf ${App}/build/*
	rm -rf ${BootLoader}/build/*
	rm -rf output/*
	make clean -C ${Settings}
	make clean -C ${GenerateBin}

# rm -rf ${BinCreater}/*

gdboot:
	${info "start flash boot "}
	pyocd flash --erase auto --target N32G430C8L7 --base-address 0x8000000 --pack=./Nations.N32G430_DFP.1.0.0.pack ./Bootloader/build/Bootloader.bin

gdapp:
	${info "start flash Application "}
	pyocd flash --erase auto --target N32G430C8L7 --base-address 0x8006000 --pack=./Nations.N32G430_DFP.1.0.0.pack ./Application/build/Application.bin 

gdsetting:
	${info "start flash settings "}
	pyocd flash --erase auto --target N32G430C8L7 --base-address 0x8004000 --pack=./Nations.N32G430_DFP.1.0.0.pack ./Settings/build/Settings.bin 

allbin:
	${info "start flash boot "}
	pyocd flash --erase auto --target N32G430C8L7 --base-address 0x8000000 --pack=./Nations.N32G430_DFP.1.0.0.pack ./output/all.bin
	